/**
 *Class AdminScreen
 *
 * version 1.0
 *
 * @author Jin Kit Chua
 * @version 20130319 V1.0
 */
package ch.zbw.iCoach.kit;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


//import ch.zbw.iCoach.kit.CreateUserScreen.ActionListenerCreate;
import ch.zbw.iCoach.remo.MainLogic;

public class AdminScreen {

	private AdminScreen as;
	private Languages la;
	// Main frame
	private JFrame mainFrame;

	private JButton addWord;
	private JButton deleteWord;
	private JButton changeSystemLang;
	private JButton help;
	private JButton close;

	private String selectedUser;

	private MainLogic ml;
	private WelcomeScreen ws;

	private JPanel buttonPanel;
	private JPanel wordPanel;

	private int langIndex;

	/**
	 * 
	 * @param ml reference for the Mainlogic to use the interface
	 * @param ws reference of the Mainscreen the app is running
	 * @param la reference to use languages
	 * @param a integer for the selected language for translation
	 * @param su String of the selected user to make the settings to
	 */
	public AdminScreen(MainLogic ml, WelcomeScreen ws, Languages la, int a,
			String su) {

		this.selectedUser = su;
		this.ws = ws;
		this.as = this;
		this.ml = ml;
		this.la = la;
		this.langIndex = a;

		this.mainFrame = new JFrame();

		this.changeSystemLang = new JButton();
		this.addWord = new JButton();
		this.deleteWord = new JButton();
		this.help = new JButton();
		this.close = new JButton();
		
		this.buttonPanel = new JPanel();
		this.wordPanel = new JPanel();

		paint();
	}

	public void paint() {


		this.mainFrame.setBackground(Color.lightGray);
		this.mainFrame.setResizable(false);
		
		String tempLang = this.la.switchLangAdmin();
		String[] parts = tempLang.split(",");
		String buttonAdd = parts[0];
		String buttonDel = parts[1];
		String buttonSys = parts[2];
		String buttonClose = parts[3];
		String buttonHelp = parts[4];
		String title = parts[5];

		this.addWord.setText(buttonAdd);
		this.deleteWord.setText(buttonDel);
		this.changeSystemLang.setText(buttonSys);
		this.close.setText(buttonClose);
		this.help.setText(buttonHelp);
		this.mainFrame.setTitle(title);

		this.wordPanel.setLayout(new GridLayout(3, 1, 10, 30));
		this.mainFrame.setLayout(new BorderLayout(10, 20));
		this.buttonPanel.setLayout(new GridLayout(4, 1, 20, 20));

		this.buttonPanel.add(this.addWord);
		this.buttonPanel.add(this.deleteWord);
		this.buttonPanel.add(this.changeSystemLang);
		this.buttonPanel.add(this.close);

		this.mainFrame.add(buttonPanel, BorderLayout.WEST);
		this.mainFrame.add(wordPanel, BorderLayout.CENTER);
//		this.mainFrame.add(this.help, BorderLayout.SOUTH);
		this.mainFrame.setSize(800, 500);
		this.mainFrame.setVisible(true);
		this.mainFrame.setLocation(450, 250);

		this.addWord.addActionListener(new ActionListenerAddWord());
		this.deleteWord.addActionListener(new ActionListenerDeleteWord());
		this.close.addActionListener(new ActionListenerClose());
		this.changeSystemLang.addActionListener(new ActionListenerChangeLang());
	}

	public void close() {
		this.mainFrame.dispose();
	}

	class ActionListenerChangeLang implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			new ChangeLang(ws, as, langIndex, la);
		}
	}

	class ActionListenerAddWord implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			new AddWordScreen(ml, la, selectedUser);
		}
	}

	class ActionListenerDeleteWord implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			new DeleteWordScreen(ml, la);
		}
	}

	class ActionListenerClose implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			new CloseScreenAdmin(as, la);
		}
	}
}
